package com.yoomiito.app.ui.anyview.goodsinfo.bottom

import android.content.Context
import android.graphics.drawable.GradientDrawable
import android.view.View
import android.widget.LinearLayout
import com.yoomiito.app.R
import com.yoomiito.app.base.App
import com.yoomiito.app.base.BaseActivity
import com.yoomiito.app.isEmptyOr0
import com.yoomiito.app.model.bean.GoodsDetail
import com.yoomiito.app.removeDecimalPoint
import com.yoomiito.app.ui.goods.NewGoodsInfoActivity
import com.yoomiito.app.ui.order.sureorder.singleGoods.BuyGoodsActivity
import com.yoomiito.app.utils.*
import kotlinx.android.synthetic.main.view_goodsinfo_bottombar.view.*

class NewYouPinBottomBar(context: BaseActivity<*>) :BaseBottomBar(context){
    override fun getLayoutId(): Int = R.layout.view_goodsinfo_bottombar

    override fun getParentView(): LinearLayout = this

    override fun initView(goodsDetail: GoodsDetail) {
        val drawable = leftBtn.background as GradientDrawable
        val radius = DensityUtil.dp2px(24f).toFloat()
        drawable.cornerRadius = radius
        val drawable1 = rightBtn.background as GradientDrawable
        drawable1.cornerRadius = radius
        goHome.setOnClickListener {
            RouterUtils.toMain(context ,0)
        }

        leftBtn.setOnClickListener {
            if (App.mAppConfig.isLogin){
                showShareDialog()
            }else{
//                AllUtils.toLogin(context, AllCode.LoginIn)
                LoginUtils.toOneKeyLogin(context)
            }
        }

        rightBtn.setOnClickListener {
            if (App.mAppConfig.isLogin){
                BuyGoodsActivity.start(context, goodsDetail, Type.GoodsType.YouPin)
            }else{
//                AllUtils.toLogin(context, AllCode.LoginIn)
                LoginUtils.toOneKeyLogin(context)
            }
        }

        leftBtnBottomTv.visibility = if (!App.mAppConfig.isLogin || goodsDetail.get_money.isEmptyOr0()||UserInfoConfig.getRoleId()<=Type.LevelType.VIP_4) View.GONE else View.VISIBLE
        leftBtnBottomTv.text = "赚${goodsDetail.share_money.removeDecimalPoint()}元"
//        leftBtnTopTv.text = if (App.mAppConfig.isLogin) "分享赚钱" else "分享"
        rightBtnBottomTv.visibility = if(!App.mAppConfig.isLogin || (UserInfoConfig.getRoleId()<=Type.LevelType.VIP_4) or goodsDetail.get_money.isEmptyOr0()) View.GONE else View.VISIBLE
        rightBtnBottomTv.text = "省${goodsDetail.get_money.removeDecimalPoint()}元"

        if(goodsDetail.buy == 2){
            rightBtn.isEnabled = false
            rightBtn.setBackgroundResource(R.drawable.bg_tv_2)
        }else{
            rightBtn.isEnabled = true
            rightBtn.setBackgroundResource(R.drawable.bg_tv_1)

        }
    }
}